import service from '../../utils/request';
import mod from '../mod'

const pos = {
    newSale(sale) {
        return service.post(mod.pos, sale)
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    getSale(deskId) {
        return service.get(mod.pos, {params: {deskId: deskId}})
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },
    addSaleLineItem(deskId, saleLineItem) {
        return service.put(mod.pos + '/addItem?deskId=' + deskId, saleLineItem)
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },
    removeSaleLineItem(deskId, saleLineItem) {
        return service.put(mod.pos + '/deleteItem?deskId=' + deskId, saleLineItem)
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },
    dropSale(deskId) {
        return service.delete(mod.pos + '?deskId=' + deskId)
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },
    makeSale(deskId) {
        return service.put(mod.pos + '?deskId=' + deskId)
            .then(data => {
                return Promise.resolve(data)
            }).catch(err => {
                return Promise.reject(err)
            })
    },

}

export default pos;